package com.woyowodaows.fragment.viewpager;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;

/**
 * @author haiwei
 *         viewPager基础适配器
 */

public class MyFragmentPagerAdapter extends FragmentPagerAdapter {

    private ArrayList<String> mTitles;
    private ArrayList<Fragment> mFragments;

    public MyFragmentPagerAdapter(FragmentManager fm, ArrayList<String> mTitles, ArrayList<Fragment> mFragments) {
        super(fm);
        this.mFragments = mFragments;
        this.mTitles = mTitles;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mTitles != null && mTitles.size() > 0) {
            return mTitles.get(position);
        } else {
            return null;
        }
    }

    public void setmTitles(ArrayList<String> mTitles) {
        this.mTitles = mTitles;
        notifyDataSetChanged();
    }

}
